package org.fuys.etp.repo.converter;

import org.fuys.etp.core.model.vo.*;
import org.fuys.etp.repo.po.*;

import java.util.Arrays;

/**
 * @projectName: fuys-etp-final
 * @package: org.fuys.etp.repo.converter
 * @className: VoToPoConverter
 * @author: WangJing
 * @description: TODO
 * @date: 2025/3/3 15:01
 * @version: 1.0
 */
public class VoToPoConverter {

    public static EtpConfigHistory converter(TpConfigHistoryVO historyVO){
        EtpConfigHistory history = new EtpConfigHistory();
        history.setChangeTime(historyVO.getChangeTime());
        history.setChangeType(historyVO.getChangeType());
        history.setChangeUserId(historyVO.getChangeUserId());
        history.setCurrentConfigVersion(historyVO.getCurrentConfigVersion());
        history.setHistoryId(historyVO.getHistoryId());
        history.setPoolName(historyVO.getPoolName());
        history.setPoolType(historyVO.getPoolType());
        history.setPreviousConfigVersion(historyVO.getPreviousConfigVersion());
        return history;
    }

    public static EtpFixedConfig converter(TpFixedConfigVO configVO){
        EtpFixedConfig config = new EtpFixedConfig();
        config.setFixedVersion(configVO.getFixedVersion());
        config.setLoadRating(configVO.getLoadRating());
        config.setScaleCompareType(configVO.getScaleCompareType());
        config.setScaleNum(configVO.getScaleNum());
        config.setScaleNumType(configVO.getScaleNumType());
        config.setExpansionCompareType(configVO.getExpansionCompareType());
        config.setExpansionNum(configVO.getExpansionNum());
        config.setExpansionNumType(configVO.getExpansionNumType());
        config.setBaseConfigVersion(configVO.getBaseConfigVersion());
        return config;
    }

    public static EtpDynamicConfig converter(TpDynamicConfigVO configVO){
        EtpDynamicConfig config = new EtpDynamicConfig();
        config.setDynamicVersion(configVO.getDynamicVersion());
        config.setMaxCoreThreadStep(configVO.getMaxCoreThreadStep());
        config.setMaxMaxThreadStep(configVO.getMaxMaxThreadStep());
        config.setMaxQueueSizeStep(configVO.getMaxQueueSizeStep());
        config.setWindowsChangeTrend(configVO.getWindowsChangeTrend());
        config.setPidKp(configVO.getPidKp());
        config.setPidKi(configVO.getPidKi());
        config.setPidKd(configVO.getPidKd());
        config.setPidTarget(configVO.getPidTarget());
        config.setBaseConfigVersion(config.getBaseConfigVersion());
        config.setLoadLevel(configVO.getLoadLevel());
        config.setWindowSize(configVO.getWindowsSize());
        config.setWindowMinSize(configVO.getWindowMinSize());
        config.setWindowWeights(Arrays.toString(configVO.getWindowWeights()));
        return config;
    }

    public static EtpBaseConfig converter(TpBaseConfigVO configVO){
        EtpBaseConfig config = new EtpBaseConfig();
        config.setPoolCoreSize(configVO.getPoolCoreSize());
        config.setPoolMaxSize(configVO.getPoolMaxSize());
        config.setPoolKeepAliveTime(configVO.getPoolKeepAliveTime());
        config.setPoolAliveTimeUnit(configVO.getPoolAliveTimeUnit());
        config.setWorkQueueSize(configVO.getWorkQueueSize());
        config.setSelfCheckInterval(configVO.getSelfCheckInterval());
        config.setSelfCheckIntervalUnit(configVO.getSelfCheckIntervalUnit());
        config.setRejectHandleBean(configVO.getRejectHandleBean());
        config.setRejectCheckThreshold(configVO.getRejectCheckThreshold());
        config.setRejectAlertThreshold(configVO.getRejectAlertThreshold());
        config.setCpuPointLimit(configVO.getCpuPointLimit());
        config.setMemoryPointLimit(configVO.getMemoryPointLimit());
        config.setDescription(configVO.getDescription());
        config.setVersion(configVO.getVersion());
        return config;
    }

    public static EtpStrategy converter(TpRegulationStrategyVO strategyVO){
        EtpStrategy strategy = new EtpStrategy();
        strategy.setStrategyId(strategyVO.getStrategyId());
        strategy.setStrategyName(strategyVO.getStrategyName());
        strategy.setStrategyDesc(strategyVO.getStrategyDesc());
        strategy.setStrategyType(strategyVO.getStrategyType());
        strategy.setAlertLevel(strategyVO.getAlertLevel());
        strategy.setLoadChain(Arrays.toString(strategyVO.getLoadChain().toArray()));
        strategy.setStartLoadLevel(strategyVO.getStartLoadLevel());
        strategy.setAlertType(strategyVO.getAlertType());
        strategy.setCheckerChain(strategyVO.getCheckerChain());
        strategy.setMetricsChain(strategyVO.getMetricsChain());
        strategy.setAlertTo(strategyVO.getAlertTo());
        return strategy;
    }
}
